﻿using System;
using GDIT.Base.PageBaseHelper;
using GDIT.BLL;
using GDIT.Model;

namespace GDIT.page.manage.content
{
    public partial class editor : System.Web.UI.Page
    {

        public string url = string.Empty;
        private BCollegeInfo college = null;
        private Mtb_CollegeInfo collegeInfo = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(Session["UserName"].ToString()))
                {
                    PageBase.MessageBoxShowAndGo("检查到你还没有登录，请先登录，谢谢！", "~/page/manage/login.aspx", Page);
                    return;
                }
                this.txtId.Text = Request.QueryString["id"];
                this.txtType.Text = Request.QueryString["type"];
                url = "http://" + Request.Url.Host + ":" + Request.Url.Port + "/Admin/fckeditor/asp.net/upload.aspx";
            }
            catch (Exception ex)
            {
                PageBase.MessageBoxShow("操作失败，原因：" + ex.Message.ToString(), Page);
            }
        }

        /// <summary>
        /// 发布
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnPublish_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtType.Text == "general")
                {
                    //发布学校概况
                    college = new BCollegeInfo();
                    collegeInfo = new Mtb_CollegeInfo();
                    collegeInfo.CollegeInfoName = this.txtTitle.Text.Trim();
                    collegeInfo.CollegeInfoContent = this.content1.Value;
                    collegeInfo.CollegeType = "general";
                    bool result = college.InsertCollegeInfo(collegeInfo);
                    if (!result)
                    {
                        PageBase.MessageBoxShow("抱歉，发布失败!", Page);
                        return;
                    }
                    else
                    {
                        PageBase.MessageBoxShow("发布成功！", Page);
                    }
                }
                else if (txtType.Text == "life")
                {
                    //发布校园生活
                    college = new BCollegeInfo();
                    collegeInfo = new Mtb_CollegeInfo();
                    collegeInfo.CollegeInfoName = this.txtTitle.Text.Trim();
                    collegeInfo.CollegeInfoContent = this.content1.Value;
                    collegeInfo.CollegeType = "life";
                    bool result = college.InsertCollegeInfo(collegeInfo);
                    if (!result)
                    {
                        PageBase.MessageBoxShow("抱歉，发布失败!", Page);
                        return;
                    }
                    else
                    {
                        PageBase.MessageBoxShow("发布成功！", Page);
                    }
                }
            }
            catch (Exception ex)
            {
                PageBase.MessageBoxShow("操作失败，原因：" + ex.Message.ToString(), Page);
            }

            //部门根据用户
        }

        /// <summary>
        /// 保存通知，修改通知
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtType.Text == "general")
                {
                    //发布学校概况
                    college = new BCollegeInfo();
                    collegeInfo = new Mtb_CollegeInfo();
                    collegeInfo.OID = Convert.ToInt32(this.txtId.Text.Trim());
                    collegeInfo.CollegeInfoName = this.txtTitle.Text.Trim();
                    collegeInfo.CollegeInfoContent = this.content1.Value;
                    collegeInfo.CollegeType = "general";
                    bool result = college.UpdateCollegeInfo(collegeInfo);
                    if (!result)
                    {
                        PageBase.MessageBoxShow("抱歉，更新失败!", Page);
                        return;
                    }
                    else
                    {
                        PageBase.MessageBoxShow("更新成功！", Page);
                    }
                }
                else if (txtType.Text == "life")
                {
                    //发布校园生活
                    college = new BCollegeInfo();
                    collegeInfo = new Mtb_CollegeInfo();
                    collegeInfo.CollegeInfoName = this.txtTitle.Text.Trim();
                    collegeInfo.OID = Convert.ToInt32(this.txtId.Text.Trim());
                    collegeInfo.CollegeInfoContent = this.content1.Value;
                    collegeInfo.CollegeType = "life";
                    bool result = college.UpdateCollegeInfo(collegeInfo);
                    if (!result)
                    {
                        PageBase.MessageBoxShow("抱歉，更新失败!", Page);
                        return;
                    }
                    else
                    {
                        PageBase.MessageBoxShow("更新成功！", Page);
                    }
                }
            }
            catch (Exception ex)
            {
                PageBase.MessageBoxShow("操作失败，原因：" + ex.Message.ToString(), Page);
            }
        }
    }
}